package com.sunday.pinxinghui.model.login;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;

import com.sunday.common.base.BaseActivity;
import com.sunday.common.utils.SharePerferenceUtils;
import com.sunday.common.utils.StatusBarUtil;
import com.sunday.pinxinghui.MainActivity;
import com.sunday.pinxinghui.R;
import com.sunday.pinxinghui.base.MyBaseActivity;
import com.yanzhenjie.alertdialog.AlertDialog;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.Rationale;
import com.yanzhenjie.permission.RationaleListener;

import butterknife.Bind;
import butterknife.ButterKnife;

import static android.Manifest.permission.READ_PHONE_STATE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;

/**
 * Created by 刘涛 on 2017/8/28.
 */

public class SplashActivity extends MyBaseActivity {


    @Bind(R.id.splash_image)
    ImageView splashView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        ButterKnife.bind(this);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        boolean isFirst = SharePerferenceUtils.getIns(mContext).getBoolean("is_first", true);
        if (isFirst) {
            intent = new Intent(mContext, GuideActivity.class);
            startActivity(intent);
            finish();
        } else {

            AlphaAnimation animation = new AlphaAnimation(0.3f, 1.0f);
            animation.setDuration(2000);
            splashView.startAnimation(animation);
            animation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    checkSdCardPermission();

                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
        }
    }

    @Override
    public void onRequestLocPermissionSuccessed() {

    }

    @Override
    public void onLocSucceed() {

    }

    @Override
    public void onLocFailed() {

    }

    @Override
    public void onRequestSdSucceed() {
        intent = new Intent(mContext, MainActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (AndPermission.hasPermission(mContext, WRITE_EXTERNAL_STORAGE, READ_PHONE_STATE)) {
            intent = new Intent(mContext, MainActivity.class);
            startActivity(intent);
            finish();
        }
    }

}
